package cn.bluethink.eguan.core.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.bluethink.eguan.filter.OtypeFilter;
import cn.bluethink.eguan.model.core.EgConfigInfo;
import cn.bluethink.eguan.model.core.EgRole;
import cn.bluethink.eguan.result.PageInfo;
import cn.bluethink.eguan.result.ResponseMessage;
import cn.bluethink.eguan.result.ResponseResult;

/**
 * eguan+角色控制器
 * 
 * @title 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1.0
 * @describe
 * @author liuxn
 * @date 2018年11月14日
 * @note 修订历史： （1）liuxn于2018年11月14日构建初始版本0.1 
 */
@CrossOrigin
@RestController
@RequestMapping("/eguan/v1.0/role")
public class EgRoleController {

	@Autowired
	private EgConfigInfo configInfo;
	
	@PostMapping("/query")
	public ResponseResult<PageInfo<EgRole>> roles(@RequestBody OtypeFilter filter) throws Exception {
		Integer otype = filter.getOtype();
		List<EgRole> result = new ArrayList<>();
		Map<Integer, EgRole> map = configInfo.roles();
		if(otype != null) 
			map.containsKey(otype);
		result = map.values().stream().collect(Collectors.toList());
		return new ResponseResult<>(ResponseMessage.OK, new PageInfo<>(result));
	}
}
